package cn.sumpu.app.guoguojie.biz.impl;



import java.util.List;

import org.springframework.transaction.annotation.Transactional;


import cn.sumpu.app.guoguojie.biz.ExperBiz;
import cn.sumpu.app.guoguojie.dao.ExperDao;
import cn.sumpu.app.guoguojie.domain.Detail;
import cn.sumpu.app.guoguojie.domain.Learning;
import cn.sumpu.app.guoguojie.domain.Work;
import cn.sumpu.app.guoguojie.exception.AppBusinessException;
import cn.sumpu.app.guoguojie.util.Common;

public class ExperBizImpl implements ExperBiz {

	private ExperDao experDao;
	
	public void setExperDao(ExperDao experDao) {
		this.experDao = experDao;
	}

	@Override
	public List<Learning> getLearningList(String member)
			throws AppBusinessException {
		return experDao.getLearningList(member);
	}
	
	@Override
	public Learning getLearningById(Integer id)
			throws AppBusinessException {
		
		return experDao.getLearningById(id);
	}

	@Override
	public List<Work> getWorkList(String member) throws AppBusinessException {
		return experDao.getWorkList(member);
	}

	@Override
	@Transactional(rollbackForClassName = { "cn.sumpu.app.guoguojie.exception.AppBusinessException" }, timeout = 10)
	public void saveExper(Detail detail) throws AppBusinessException {
		if(detail == null) return ;
		List<Learning> learningList = detail.getLearningList();
		List<Work> workList = detail.getWorkList();
		experDao.deleteLearning(detail.getMember());
		experDao.deleteWork(detail.getMember());
		for (Learning learning : learningList) {
			learning.setMember(detail.getMember());
			experDao.insertLearning(learning);
		}
		for (Work work : workList) {
			work.setMember(detail.getMember());
			experDao.insertWork(work);
		}
		
	}

	@Override
	public void updateLearning(Learning learning) throws AppBusinessException {
		experDao.updateLearning(learning);
	}

	@Override
	public void deleteLearningById(Integer id) throws AppBusinessException {
		experDao.deleteLearningById(id);
	}

	@Override
	public void updateWork(Work work) throws AppBusinessException {
		experDao.updateWork(work);
	}

	@Override
	public void deleteWorkById(Integer id) throws AppBusinessException {
		experDao.deleteWorkById(id);
	}

	@Override
	public void saveLearning(Learning learning) throws AppBusinessException {
		if(learning==null)return ;
		if(Common.empty(learning.getId())){
			if(!"".equals(learning.getSchool()) && learning.getSchool() != null)
				experDao.insertLearning(learning);
		}else{
			experDao.updateLearning(learning);
		}
	}	

	@Override
	public void saveWork(Work work) throws AppBusinessException {
		if(work==null)return ;
		if(Common.empty(work.getId())){
			experDao.insertWork(work);
		}else{
			experDao.updateWork(work);
		}
	}

	@Override
	public Work getWorkById(Integer id) throws AppBusinessException {
		return experDao.getWorkById(id);
	}

	
	

}
